<?php
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'autoload.php';

use payClass\Datebase;
use payClass\QRcode;
use payClass\pay\Config;

/**
 * 网关支付
 */
class Gateway
{
	public static function payDo()
	{
		$db     = new Datebase();

		$config = new Config();

		$param = $db->param();

		// 订单号
		$param['orderNumber'] = 'C' . time() . 'U' . $param['uid'];

		$param['paytype'] = Config::$folder.'-'.Config::$merchant;
		// 数据检测
		$verifyRes = $db->verifyOnline($param);

		if ($verifyRes != 'Y') $db->ajaxReturn($verifyRes);

		$data = [
			'pay_memberid'    => Config::$merchant,
			'pay_orderid'     => $param['orderNumber'],
			'pay_applydate'   => date('Y-m-d H:i:s'),
			'pay_bankcode'    => $param['bank_code'],
			'pay_notifyurl'   => Config::$notifyUrl,
			'pay_callbackurl' => Config::$merUrl,
			'pay_amount'      => sprintf("%.2f", $param['price']),
			'pay_name'        => $param['pay_name'],
			'pay_mobile'      => $param['pay_mobile'],
			'pay_account'     => $param['pay_account'],
			'pay_email'       => $param['pay_email'],
			// 'pay_name'        => 'rohit',
			// 'pay_mobile'      => '+91 9876660001',
			// 'pay_account'     => '001205455210',
			// 'pay_email'       => '100',
		];
		// 生成签名
		$data['pay_md5sign'] = Config::getSignMsg($data);

		$data['subUrl'] = Config::$subUrl . 'Pay_Index.html';

		return $data;
		// // 发送请求
		// $curlRes             = Config::setHttpRequest(Config::$subUrl . 'Pay_Index.html', $data);
		// print_r($curlRes);die;
		// // JSON解码
		// $resArray            = json_decode($curlRes, true);

		// if (!$resArray['payment']) $db->ajaxReturn($resArray['message']);

		// $db->ajaxReturn($resArray['payUrl']);
	}
}

$data = Gateway::payDo();

?>

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title></title>
	<link rel="stylesheet" href="">
</head>
<body>
	<form action="<?=$data['subUrl']?>" method="post" id="formid">
		<?php foreach ($data as $key => $value) {
			echo '<input type="hidden" name="'.$key.'" value="'.$value.'"><br>';
		} ?>
	</form>
	<script type="text/javascript">
		document.getElementById('formid').submit();
	</script>
</body>
</html>
